package com.hualan.sfzy.service.course.impl;

import com.hualan.sfzy.entity.CourseComment;
import com.hualan.sfzy.mapper.course.CourseCommentMapper;
import com.hualan.sfzy.service.course.CourseCommentService;
import com.hualan.sfzy.vo.CourseCommentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@Service
public class CourseCommentServiceImpl implements CourseCommentService {
    @Autowired
    private CourseCommentMapper courseCommentMapper;
    @Override
    public int add(CourseComment entity) {
        System.out.println(entity);
        entity.setTime(new Date());
        entity.setDel(0);
        return courseCommentMapper.insert(entity);
    }

    @Override
    public int edit(CourseComment entity) {
        return courseCommentMapper.update(entity);
    }

    @Override
    public int remove(Integer id) {
        return courseCommentMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return courseCommentMapper.deleteBatch(ids);
    }

    @Override
    public List<CourseComment> find() {
        return courseCommentMapper.selectAll();
    }
    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, CourseComment entity) {
        PageHelper.startPage(pageNum,pageSize);
        List<CourseComment> courseComments = courseCommentMapper.select(entity);
        PageInfo<CourseComment> pageInfo = new PageInfo<>(courseComments);
        Map<String, Object> result = new HashMap<>();
        result.put("list", pageInfo.getList());
        result.put("total", pageInfo.getTotal());
        result.put("pageNum", pageInfo.getPageNum());
        result.put("pageSize", pageInfo.getPageSize());
        result.put("pages", pageInfo.getPages());
        return result;
    }
    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, CourseCommentVo entity) {
        PageHelper.startPage(pageNum,pageSize);
        List<CourseCommentVo> courseCommentVos = courseCommentMapper.selectVo(entity);
        PageInfo<CourseCommentVo> pageInfo = new PageInfo<>(courseCommentVos);
        Map<String, Object> result = new HashMap<>();
        result.put("list", pageInfo.getList());
        result.put("total", pageInfo.getTotal());
        result.put("pageNum", pageInfo.getPageNum());
        result.put("pageSize", pageInfo.getPageSize());
        result.put("pages", pageInfo.getPages());
        return result;
    }

    @Override
    public CourseComment findById(Integer id) {
        return courseCommentMapper.selectById(id);
    }
}
